package com.ffs.game.scene.obj.ai;

import com.ffs.game.common.entity.Vector2f;
import com.ffs.game.scene.GameScene;
import com.ffs.game.scene.obj.Monster;
import com.ffs.game.utils.RandomUtil;

/**
 * 巡逻怪AI
 *
 * @author ffs80
 */
public class PatrolAI extends AbstractAI {

    @Override
    public void bornUpdate(GameScene screen, Monster monster, int dt) {
        super.bornUpdate(screen, monster, dt);
        patrol(screen, monster);
    }

    /**
     * 巡逻
     */
    public void patrol(GameScene screen, Monster monster) {
        int patrolTime = monster.getMonsterMachine().getAiData().getPatrolInterval();
        if (patrolTime <= 0) {
            //随机一个方向
            int w = RandomUtil.randomInt(0, 50);
            Vector2f nextPoint = RandomUtil.calcNextPoint(monster.getVector2f(), w, monster.getPatrolRadius());
            monster.setNextVector2f(nextPoint);
            int nextPatrolTime = RandomUtil.randomInt(1000, 2000);
            monster.getMonsterMachine().getAiData().setPatrolInterval(nextPatrolTime);
        }

        MoveManager.getInstance().move(screen, monster);
    }
}
